﻿Imports System.Configuration
Imports System.Windows



Public Class Configurator

    Implements iConverter.Contracts.IPluginConfigurator

    Private Property Settings As My.MySettings

    Public Sub Load(Settings As System.Configuration.ApplicationSettingsBase) Implements iConverter.Contracts.IPluginConfigurator.Load
        Me.Settings = TryCast(Settings, My.MySettings)

    End Sub

    Public Sub Unload(Settings As System.Configuration.ApplicationSettingsBase) Implements iConverter.Contracts.IPluginConfigurator.Unload
        Me.Settings = Nothing
    End Sub


    ''' <summary>
    ''' 删除
    ''' </summary>
    Private Sub btnDelete_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnDelete.Click
        If Me.Settings IsNot Nothing AndAlso
            Me.Settings.Dictionary.Count > 0 AndAlso
            Me.lstDictionary.SelectedItem IsNot Nothing Then


            Me.Settings.Dictionary.Remove(Me.lstDictionary.SelectedValue)

        End If
    End Sub

    ''' <summary>
    ''' 添加
    ''' </summary>
    Private Sub btnAdd_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnAdd.Click

        Dim s = Me.txtSimplified.Text.Trim

        Dim t = Me.txtTraditional.Text.Trim

        If String.IsNullOrEmpty(s) OrElse String.IsNullOrEmpty(t) Then
            MessageBox.Show("简体字段和繁体字段不能为空！")

            Return
        End If


        If Me.Settings IsNot Nothing Then

            Me.Settings.Dictionary.Add(s, t)

        End If
    End Sub
End Class
